<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      :height="$store.state.app.tableHeight"
    >
      <el-table-column
        fixed
        prop="warehouse_name"
        label="仓库名称"
      />
      <el-table-column
        prop="company"
        label="公司"
      />
      <el-table-column
        prop="desc"
        label="名称描述"
      />
      <el-table-column
        prop="address"
        label="地址"
      />
      <el-table-column
        prop="place"
        label="场所"
      />
      <el-table-column
        fixed="right"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleCheck(scope.row)">查看</el-button>
          <el-button type="text" size="small" @click="handleClick(scope.row)">修改</el-button>
          <del-btn :title="'是否确认删除名称为 “' + scope.row.warehouse_name + '” 的仓库？'" button-text="删除" @onConfirm="delWarehouseInfo(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
    <warehouse-info-dialog ref="warehouseInfoForm" :title="dialogTitle" @reloadData="reloadData" />
  </div>
</template>

<script>
import warehouseInfoDialog from './warehouse-info-dialog'
import delBtn from '@/components/DelConfirm'
import { operationWarehouseInfo } from '@/api/wms'
export default {
  components: {
    warehouseInfoDialog,
    delBtn
  },
  props: {
    tableData: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      visible: false,
      dialogTitle: ''
    }
  },
  created() {
  },
  methods: {
    handleClick(row) {
      this.dialogTitle = '修改'
      this.$refs.warehouseInfoForm.dialogAddNew = true
      this.$refs.warehouseInfoForm.form = JSON.parse(JSON.stringify(row))
      this.$refs.warehouseInfoForm.type = 2
      this.$refs.warehouseInfoForm.isDisable = false
    },
    handleCheck(row) {
      this.dialogTitle = '查看'
      this.$refs.warehouseInfoForm.dialogAddNew = true
      this.$refs.warehouseInfoForm.form = JSON.parse(JSON.stringify(row))
      this.$refs.warehouseInfoForm.type = 2
      this.$refs.warehouseInfoForm.isDisable = true
    },
    reloadData() {
      this.$emit('reloadData')
    },
    delWarehouseInfo(row) {
      const data = {
        type: 3,
        id: row.id
      }
      operationWarehouseInfo(data).then(res => {
        if (res.code === 200) {
          this.$message.success('仓库信息删除成功！')
          this.$emit('reloadData')
        }
      })
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
